/*
 * @lc app=leetcode.cn id=202 lang=cpp
 *
 * [202] 快乐数
 */
#include <iostream>
// @lc code=start
class Solution
{
private:
  int get_next_num(int num)
  {
    int new_num = 0;
    while (num) {
      int tmp = num % 10;
      num /= 10;
      new_num += tmp * tmp;
    }
    return new_num;
  }

public:
  bool isHappy(int n)
  {
    int slow = n, fast = n;
    do {
      slow = get_next_num(slow);
      fast = get_next_num(get_next_num(fast));
    } while (fast != slow);
    return slow == 1;
  }
};
// @lc code=end

int main() {}
